<template>
  <div>
    <el-form ref="dataForm" :model="form" label-width="90px">
      <div class="ledgerTitle">基本信息</div>
      <el-row>
        <el-col :span="8">
          <el-form-item label-width="110px" label="项目名称: " prop="projectName">
            {{ form.projectName }}
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label-width="110px" label="建设单位:" prop="auditedCompanyName">
            {{ form.auditedCompanyName }}
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label-width="140px" label="建设单位联系人:" prop="auditedUserNames">
            {{ form.auditedCompanyUserName }}
          </el-form-item>
        </el-col>
      </el-row>
      <div class="ledgerTitle">工作安排</div>
      <el-row>
        <el-col :span="12">
          <el-form-item label-width="110px" label="协审单位:" prop="assistCompanyName">
            {{ form.assistCompanyName }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label-width="110px" label="协审单位组长:" prop="assistLeader">
            {{ form.assistLeader }}
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col>
          <el-form-item label-width="110px" label="审计组成员:" prop="assistMembers">
            {{ form.assistMembers }}
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import {getApply} from "@/api/adis/project/projectApply";

export default {
  name: 'EngineeringApplyAuditView',
  props: {
    id: {
      type: String,
      default: ''
    },
    params: {
      type: Object,
    },
    isAudit: {
      type: Boolean,
      default: false,
    }
  },
  components: {},
  dictTypes: ['audit_type', 'audit_type_1_sub', 'project_progress', 'audit_way', 'organization_type'],
  data() {
    return {
      form: {},
    }
  },
  watch:{
    id: {
      handler(val) {
        if (val) {
          getApply(this.id).then(applyResponse => {
            if (applyResponse.data.data !== null){
              this.handleApplyResponse(applyResponse.data.data)
              this.$emit('data-loaded', true);
            } else {
              this.$emit('data-loaded', false);
            }
          }).catch(() => {
            this.$emit('data-loaded', false);
          })
        }
      },deep: true, immediate: true
    },
    params: {
      handler(val) {
        if (val) {
          this.handleApplyResponse(val)
        }
      },deep: true, immediate: true
    }
  },
  methods: {
    handleApplyResponse(val) {
      if(val.auditStartDate && val.auditEndDate) {
        val.auditDates = [val.auditStartDate, val.auditEndDate];
      }
      if(val.workStartDate && val.workEndDate) {
        val.workDates = [val.workStartDate, val.workEndDate];
      }
      if(val.projectStartDate && val.projectEndDate) {
        val.projectDates = [val.projectStartDate, val.projectEndDate];
      }
      val.createDate = val.projectDate
      this.$set(this, "form", val);
    },
    openWord() {
      if(!this.form.wordFile) {
        this.$message({
          type: "warning",
          message: "该项尚未上传相关文书!"
        });
        return;
      }
      // this.$router.push({path:'/webOffice', query: {url: this.form.wordFile}})
      const { href } = this.$router.resolve({
        path: '/webOffice',
        query: {
          url: this.form.wordFile,
          type: this.isAudit ? 'edit' : 'view',
        }
      });
      window.open(href, '_blank');
    }
  }
}
</script>

